package com.edu.imau.TParking;

import com.edu.imau.FixedParking.Fixed;
import com.edu.imau.ParkingDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/TemporaryAdd")
public class TAddServlet extends HttpServlet {
    private ParkingDao dao = new ParkingDao();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 处理参数
        String t_id = request.getParameter("t_id");
        String t_name =request.getParameter("t_name");
        String t_brand =request.getParameter("t_brand");
        String t_cnumber =request.getParameter("t_cnumber");
        String t_pnumber =request.getParameter("t_pnumber");
        String t_btime =request.getParameter("t_btime");
        String t_etime =request.getParameter("t_etime");
        //2 调用model
        if(t_id == null||t_id.equals("")){
            Temporary temporary = new Temporary(-1,t_name,t_brand,t_cnumber,
                    t_pnumber,t_btime,t_etime);
            dao.addTemporary(temporary);
        }else{
            Temporary temporary = new Temporary(Integer.parseInt(t_id),t_name,t_brand,t_cnumber,
                    t_pnumber,t_btime,t_etime);
            dao.updateTemporary(temporary);
        }
        //3 数据交给View
        response.sendRedirect("Temporary.jsp");
    }
}
